//
//  UIButton+Extension.swift
//  WeiBoSwift
//
//  Created by admin on 2017/12/5.
//  Copyright © 2017年 admin. All rights reserved.
//

import UIKit

extension UIButton {
    class func create(imageName : String, backgroundImageName : String) -> UIButton {
        let btn = UIButton()
        
        btn.setImage(UIImage.init(named: imageName), for: .normal)
        btn.setImage(UIImage.init(named: imageName), for: .highlighted)
        btn.setBackgroundImage(UIImage.init(named: backgroundImageName), for: .normal)
        btn.setBackgroundImage(UIImage.init(named: backgroundImageName + "_highlighted"), for: .highlighted)
        
        btn.sizeToFit()
        return btn
    }
    
    // 便利构造方法
    convenience init(imageName : String, backgroundImageName : String) {
        self.init()
        
        setImage(UIImage.init(named: imageName), for: .normal)
        setImage(UIImage.init(named: imageName), for: .highlighted)
        setBackgroundImage(UIImage.init(named: backgroundImageName), for: .normal)
        setBackgroundImage(UIImage.init(named: backgroundImageName + "_highlighted"), for: .highlighted)
        
        sizeToFit()
    }
}
